package net.member.action;

import java.io.PrintWriter;
import java.sql.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.member.db.MemberBean;
import net.member.db.MemberDAO;

public class MemberAddAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		request.setCharacterEncoding("utf-8");
		ActionForward forward = new ActionForward();
		MemberBean memberbean = new MemberBean();
		MemberDAO memberdao = new MemberDAO();
		HttpSession session = request.getSession();
		
		memberbean.setMember_id(request.getParameter("member_id"));
		memberbean.setMember_name(request.getParameter("member_name"));
		memberbean.setMember_pw(request.getParameter("member_pw"));
		memberbean.setMember_jumin1(Integer.parseInt(request.getParameter("member_jumin1")));
		memberbean.setMember_jumin2(Integer.parseInt(request.getParameter("member_jumin2")));
		memberbean.setMember_email(request.getParameter("member_email1")+"@"+request.getParameter("member_email2"));
		memberbean.setMember_email_get(request.getParameter("member_email_get"));
		memberbean.setMember_phone(request.getParameter("member_phone"));
		memberbean.setMember_zipcode(request.getParameter("member_zipcode1")+"-"+request.getParameter("member_zipcode2"));
		memberbean.setMember_addr1(request.getParameter("member_addr1"));
		memberbean.setMember_addr2(request.getParameter("member_addr2"));
		memberbean.setMember_admin(0);
		memberbean.setMember_join_date(new Date(System.currentTimeMillis()));
		
		memberdao.insertMember(memberbean);
		
		response.setContentType("text/html; charset=euc-kr");
		PrintWriter out = response.getWriter();
		out.println("<script>");
		out.println("alert('회원가입에 성공하였습니다.')");
		out.println("location.href='MemberMain.mb'");
		out.println("</script>");
		out.close();
		return forward;
	}

}
